﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace PeisongWeb
{
    public partial class buyer_pwdEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }
        protected void lbtn_Submit_Click(object sender, EventArgs e)
        {
            if (Request.Headers["Accept"] != "*/*")
            {
                string oldpwd = Library.StringLbl.EncryptMD5(this.txt_oldPassword.Text);
                int userid = logic.customer.userId;
                string sqlpwd = logic.customer.getById(userid).Password;
                if (oldpwd == sqlpwd)
                {
                    CustomerEntity _cus = new CustomerEntity();
                    _cus.CustomerId = userid;
                    _cus.Password = Library.StringLbl.EncryptMD5(txt_password.Text);
                    _cus.Oldpassword = oldpwd;
                    _cus.IP = GetClientIP();
                    logic.customer.updatePwd(_cus);
                    Library.Script.ClientMsg("修改成功！");
                }
                else
                {
                    //旧密码不正确
                    Library.Script.ClientMsg("旧密码不正确！");
                    return;
                }
            }
        }
        public static string GetClientIP()
        {
            string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (null == result || result == string.Empty)
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }

            if (null == result || result == string.Empty)
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }
            return result;
        }
    }
}
